package com.dz.scrm.utils;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.widget.TextView;

import com.dz.scrm.R;


/**
 * Created by hai.huang on 2018/5/22.
 */

public class DialogUtil {
    private static Dialog progressDialog = null;

    /**
     * 取消所有弹出的对话框
     */
    public static void dismissDialog() {
        try {
            if (progressDialog != null && progressDialog.isShowing())
                progressDialog.dismiss();
            progressDialog = null;
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /***
     *
     * @param context
     */
    public static void showProgressDialog( Context context) {
        try {
            if (context == null || ((Activity)context).isDestroyed()){
                return;
            }
            dismissDialog();
            progressDialog = new Dialog(context, R.style.progress_dialog);
            progressDialog.setContentView(R.layout.s_mydialog);
            progressDialog.setCancelable(false);
            progressDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
            TextView msg = (TextView) progressDialog.findViewById(R.id.id_tv_loadingmsg);
            msg.setText("加载中...");
            progressDialog.show();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /***
     *
     * @param context
     */
    public static void showLoginDialog( Context context) {
        dismissDialog();
        progressDialog = new Dialog(context, R.style.progress_dialog);
        progressDialog.setContentView(R.layout.s_mydialog);
        progressDialog.setCancelable(false);
        progressDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        TextView msg = (TextView) progressDialog.findViewById(R.id.id_tv_loadingmsg);
        msg.setText("登录中...");
        progressDialog.show();
    }
}
